import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from math import pi
PI = pi

def draw(path):
    # 读取数据
    data = pd.read_csv(path)
    data['angle'] = data['angle'] / 180 * PI # 单位换算

    fig = plt.figure(dpi=300)
    # step3：在画布上添加1个子块，标定绘图位置
    ax = fig.add_subplot(1, 1, 1, projection='polar')
    ax.set_thetagrids(np.arange(0.0, 360.0, 15.0))
    ax.set_thetamin(0.0)  # 设置极坐标图开始角度为0°
    ax.set_thetamax(180.0) # 最大角度
    # 标签
    max_dis = max(data['distance'])
    max_r = int(max_dis + 10)
    print(max_dis)
    ax.set_rlim(0.0, max_r)
    ax.set_rgrids(np.arange(0, max_r, max_r//5))
    ax.set_rlabel_position(0.0)  # 标签显示在0°
    ax.grid(True, linestyle="-", color="k", linewidth=0.5, alpha=0.5)

    theta = data['angle']
    r =  data['distance']

    plt.polar(theta,r, linestyle='None', marker='.',markersize=1)
    img_path = path.replace('data','img').replace('csv', 'png')
    plt.savefig(img_path,dpi=300)